home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Navigation / Navigation.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.6 KB  |  437 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14. import java.net.MalformedURLException;
  15. import java.net.URL;
  16. import java.net.URLEncoder;
  17.  
  18. public class Navigation extends Applet implements Runnable, MouseListener, MouseMotionListener {
  19.    private Thread thread;
  20.    // $FF: renamed from: wi int
  21.    private int field_0;
  22.    // $FF: renamed from: he int
  23.    private int field_1;
  24.    // $FF: renamed from: n int
  25.    private int field_2 = 1;
  26.    private boolean loaded = false;
  27.    private Image[] image;
  28.    private Image[] imagef;
  29.    private int[] width;
  30.    private int index;
  31.    // $FF: renamed from: b java.awt.Graphics
  32.    private Graphics field_3;
  33.    private Image buffer;
  34.    private boolean hor = true;
  35.    private String statusBarText;
  36.    private AudioClip sound;
  37.    private AudioClip clicSound;
  38.    private AudioClip enterSound;
  39.    private boolean loopSound;
  40.    // $FF: renamed from: fm java.awt.FontMetrics
  41.    private FontMetrics field_4;
  42.    private String enterText;
  43.    private boolean isEnterTextEnabled;
  44.    private int wiEnterText;
  45.    private int enterTextHeight;
  46.    private Color enterTextColor;
  47.  
  48.    public String getAppletInfo() {
  49.       return "Name: Navigation\r\nAuthor: Taiji Software\r\n";
  50.    }
  51.  
  52.    public Navigation() {
  53.       ((Component)this).addMouseListener(this);
  54.       ((Component)this).addMouseMotionListener(this);
  55.    }
  56.  
  57.    public void register() {
  58.       try {
  59.          URL u = new URL("http://www.taijisoftware.com");
  60.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  61.       } catch (Exception e) {
  62.          System.out.println(e);
  63.          this.stop();
  64.       }
  65.    }
  66.  
  67.    public void init() {
  68.       String codeBase = null;
  69.  
  70.       try {
  71.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  72.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  73.          codeBase = codeBase.toUpperCase();
  74.       } catch (Exception var9) {
  75.       }
  76.  
  77.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  78.          String regCode = ((Applet)this).getParameter("registration_code");
  79.          if (regCode == null) {
  80.             regCode = ((Applet)this).getParameter("reg_domain");
  81.             if (regCode == null) {
  82.                this.register();
  83.             } else {
  84.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  85.                   codeBase = "WWW." + codeBase;
  86.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  87.                   codeBase = codeBase.substring(4);
  88.                }
  89.  
  90.                char[] chars = new char[codeBase.length()];
  91.                codeBase.getChars(0, codeBase.length(), chars, 0);
  92.                String key = new String("haricot");
  93.                char[] chars2 = new char[key.length()];
  94.                key.getChars(0, key.length(), chars2, 0);
  95.  
  96.                for(int i = 0; i < codeBase.length(); ++i) {
  97.                   int j;
  98.                   if (i >= key.length()) {
  99.                      j = i - key.length() * (i / key.length());
  100.                   } else {
  101.                      j = i;
  102.                   }
  103.  
  104.                   chars[i] += chars2[j];
  105.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  106.                }
  107.  
  108.                String res = new String(chars);
  109.                if (!res.equalsIgnoreCase(regCode)) {
  110.                   this.register();
  111.                }
  112.             }
  113.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  114.             this.register();
  115.          }
  116.       }
  117.  
  118.       this.getParameters();
  119.       if (this.sound != null) {
  120.          if (this.loopSound) {
  121.             this.sound.loop();
  122.             return;
  123.          }
  124.  
  125.          this.sound.play();
  126.       }
  127.  
  128.    }
  129.  
  130.    public void getParameters() {
  131.       this.field_0 = ((Component)this).getSize().width;
  132.       this.field_1 = ((Component)this).getSize().height;
  133.       String s = ((Applet)this).getParameter("number");
  134.       if (s != null) {
  135.          this.field_2 = Integer.parseInt(s);
  136.       }
  137.  
  138.       s = ((Applet)this).getParameter("direction");
  139.       if (s.equals("vertical")) {
  140.          this.hor = false;
  141.       }
  142.  
  143.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  144.       s = ((Applet)this).getParameter("sound_name");
  145.       if (s != null) {
  146.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  147.       }
  148.  
  149.       s = ((Applet)this).getParameter("loop_sound");
  150.       if (s != null) {
  151.          if (s.equals("yes")) {
  152.             this.loopSound = true;
  153.          } else {
  154.             this.loopSound = false;
  155.          }
  156.       }
  157.  
  158.       s = ((Applet)this).getParameter("clic_sound_name");
  159.       if (s != null) {
  160.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  161.       }
  162.  
  163.       s = ((Applet)this).getParameter("enter_sound_name");
  164.       if (s != null) {
  165.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  166.       }
  167.  
  168.       this.enterText = ((Applet)this).getParameter("enter_text");
  169.       s = ((Applet)this).getParameter("enter_text_height");
  170.       if (s != null) {
  171.          this.enterTextHeight = Integer.parseInt(s);
  172.       }
  173.  
  174.       this.enterTextColor = this.getColor("enter_text_color");
  175.       if (this.enterTextColor == null) {
  176.          this.enterTextColor = Color.white;
  177.       }
  178.  
  179.    }
  180.  
  181.    public Color getColor(String param) {
  182.       String s = ((Applet)this).getParameter(param);
  183.       if (s != null) {
  184.          if (s.substring(0, 1).equals("#")) {
  185.             s = s.substring(1);
  186.             int i = Integer.parseInt(s, 16);
  187.             return new Color(i);
  188.          } else {
  189.             return null;
  190.          }
  191.       } else {
  192.          return null;
  193.       }
  194.    }
  195.  
  196.    public void start() {
  197.       if (this.thread == null) {
  198.          this.thread = new Thread(this);
  199.          this.thread.start();
  200.       }
  201.  
  202.    }
  203.  
  204.    public void stop() {
  205.       if (this.thread != null) {
  206.          this.thread = null;
  207.       }
  208.  
  209.       if (this.sound != null) {
  210.          this.sound.stop();
  211.       }
  212.  
  213.    }
  214.  
  215.    public void paint(Graphics g) {
  216.       if (this.loaded) {
  217.          int l = 0;
  218.  
  219.          for(int i = 0; i < this.field_2; ++i) {
  220.             if (i != this.index) {
  221.                if (this.hor) {
  222.                   this.field_3.drawImage(this.image[i], l, 0, this.width[i], this.field_1, this);
  223.                } else {
  224.                   this.field_3.drawImage(this.image[i], 0, l, this.field_0, this.width[i], this);
  225.                }
  226.             } else if (this.hor) {
  227.                this.field_3.drawImage(this.imagef[i], l, 0, this.width[i], this.field_1, this);
  228.             } else {
  229.                this.field_3.drawImage(this.imagef[i], 0, l, this.field_0, this.width[i], this);
  230.             }
  231.  
  232.             l += this.width[i];
  233.          }
  234.  
  235.          if (this.isEnterTextEnabled) {
  236.             this.field_3.drawString(this.enterText, (this.field_0 - this.wiEnterText) / 2, this.field_1 / 2);
  237.          }
  238.  
  239.          g.drawImage(this.buffer, 0, 0, this);
  240.       }
  241.  
  242.    }
  243.  
  244.    public void run() {
  245.       if (!this.loaded) {
  246.          this.buffer = ((Component)this).createImage(this.field_0, this.field_1);
  247.          this.field_3 = this.buffer.getGraphics();
  248.          this.field_3.setColor(this.enterTextColor);
  249.          String fontName = ((Applet)this).getParameter("enter_text_font");
  250.          if (fontName == null) {
  251.             fontName = "TimesRoman";
  252.          }
  253.  
  254.          int style = 1;
  255.          String s = ((Applet)this).getParameter("enter_text_style");
  256.          if (s != null) {
  257.             if (s.equals("bold")) {
  258.                style = 1;
  259.             } else if (s.equals("italic")) {
  260.                style = 2;
  261.             } else if (s.equals("bold_italic")) {
  262.                style = 3;
  263.             } else {
  264.                style = 0;
  265.             }
  266.          }
  267.  
  268.          this.field_3.setFont(new Font(fontName, style, this.enterTextHeight));
  269.          this.field_4 = this.field_3.getFontMetrics();
  270.          if (this.enterText != null) {
  271.             this.wiEnterText = this.field_4.stringWidth(this.enterText);
  272.          }
  273.  
  274.          this.image = new Image[this.field_2];
  275.          this.imagef = new Image[this.field_2];
  276.          MediaTracker tracker = new MediaTracker(this);
  277.  
  278.          for(int i = 1; i <= this.field_2; ++i) {
  279.             this.image[i - 1] = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image" + Integer.toString(i)));
  280.             this.imagef[i - 1] = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_focused" + Integer.toString(i)));
  281.          }
  282.  
  283.          for(int i = 0; i < this.field_2; ++i) {
  284.             tracker.addImage(this.image[i], 0);
  285.             tracker.addImage(this.imagef[i], 0);
  286.          }
  287.  
  288.          try {
  289.             tracker.waitForAll();
  290.             this.loaded = !tracker.isErrorAny();
  291.          } catch (Exception e) {
  292.             System.out.println(e);
  293.          }
  294.  
  295.          if (!this.loaded) {
  296.             this.stop();
  297.          }
  298.  
  299.          this.width = new int[this.field_2];
  300.  
  301.          for(int i = 0; i < this.field_2; ++i) {
  302.             if (this.hor) {
  303.                this.width[i] = this.image[i].getWidth(this);
  304.             } else {
  305.                this.width[i] = this.image[i].getHeight(this);
  306.             }
  307.          }
  308.       }
  309.  
  310.       this.repaint(-1);
  311.    }
  312.  
  313.    public void repaint(int in) {
  314.       this.index = in;
  315.       ((Component)this).repaint();
  316.    }
  317.  
  318.    public URL giveURL(String url) {
  319.       try {
  320.          if (url.toUpperCase().startsWith("HTTP")) {
  321.             return new URL(url);
  322.          } else if (url.toUpperCase().startsWith("FTP")) {
  323.             int p = url.indexOf(":");
  324.             int p2 = url.indexOf(":", p + 1);
  325.             if (p2 != -1) {
  326.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  327.             }
  328.  
  329.             p = url.indexOf("%40");
  330.             if (p != -1) {
  331.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  332.             }
  333.  
  334.             return new URL(url);
  335.          } else {
  336.             return new URL(((Applet)this).getCodeBase(), url);
  337.          }
  338.       } catch (MalformedURLException e) {
  339.          System.out.println(e);
  340.          return null;
  341.       }
  342.    }
  343.  
  344.    public void mouseClicked(MouseEvent e) {
  345.       if (this.clicSound != null) {
  346.          this.clicSound.play();
  347.       }
  348.  
  349.       int l = 0;
  350.       int xi;
  351.       if (this.hor) {
  352.          xi = e.getX();
  353.       } else {
  354.          xi = e.getY();
  355.       }
  356.  
  357.       for(int i = 0; i < this.field_2; ++i) {
  358.          if (xi > l & xi < l + this.width[i]) {
  359.             try {
  360.                String target = ((Applet)this).getParameter("target");
  361.                if (target == null) {
  362.                   target = "_self";
  363.                }
  364.  
  365.                ((Applet)this).getAppletContext().showDocument(this.giveURL(((Applet)this).getParameter("link" + Integer.toString(i + 1))), target);
  366.                return;
  367.             } catch (Exception ex) {
  368.                System.out.println(ex);
  369.                return;
  370.             }
  371.          }
  372.  
  373.          l += this.width[i];
  374.       }
  375.  
  376.    }
  377.  
  378.    public void mouseEntered(MouseEvent e) {
  379.       if (this.enterText != null) {
  380.          this.isEnterTextEnabled = true;
  381.          ((Component)this).repaint();
  382.       }
  383.  
  384.       if (this.statusBarText != null) {
  385.          ((Applet)this).showStatus(this.statusBarText);
  386.       }
  387.  
  388.       if (this.enterSound != null) {
  389.          this.enterSound.play();
  390.       }
  391.  
  392.       ((Component)this).setCursor(new Cursor(12));
  393.    }
  394.  
  395.    public void mouseExited(MouseEvent e) {
  396.       this.repaint(-1);
  397.       if (this.isEnterTextEnabled) {
  398.          this.isEnterTextEnabled = false;
  399.          ((Component)this).repaint();
  400.       }
  401.  
  402.       ((Component)this).setCursor(new Cursor(0));
  403.    }
  404.  
  405.    public void mousePressed(MouseEvent e) {
  406.    }
  407.  
  408.    public void mouseReleased(MouseEvent e) {
  409.    }
  410.  
  411.    public void mouseDragged(MouseEvent e) {
  412.    }
  413.  
  414.    public void mouseMoved(MouseEvent e) {
  415.       int l = 0;
  416.       int xi;
  417.       if (this.hor) {
  418.          xi = e.getX();
  419.       } else {
  420.          xi = e.getY();
  421.       }
  422.  
  423.       for(int i = 0; i < this.field_2; ++i) {
  424.          if (xi > l & xi < l + this.width[i]) {
  425.             if (i != this.index) {
  426.                this.repaint(i);
  427.             }
  428.  
  429.             return;
  430.          }
  431.  
  432.          l += this.width[i];
  433.       }
  434.  
  435.    }
  436. }
  437.